// 异步设置app版本号

import {
  getUserInfo
} from '@/apis/login'
import {
  setToken,
  getToken
} from '@/utils/token'
const SET_USERINFO_MUTATION = 'SET_USERINFO_MUTATION' // 设置app版本号
const SET_USERINFO_ACTION = 'SET_USERINFO_ACTION'
export default {
  state: {
    userInfo: JSON.parse(getToken('userInfo')) || {}
  },
  mutations: {
    [SET_USERINFO_MUTATION]: (state, payload) => {
      state.userInfo = payload
      setToken(JSON.stringify(payload))
    }
  },
  actions: {
    [SET_USERINFO_ACTION]: ({
      commit
    }, payload) => {
      return new Promise((resolve, reject) => {
        getUserInfo().then(
          res => {
            commit('SET_USERINFO_MUTATION', res)
            resolve(res)
            payload && payload(res)
          }
        )
      })
    }
  }
}
